/*
This is an example script for a 3D surface graphic. Click the Execute button to apply and then execute this script. Upon each execution the 3D surface alters its appearance. Turn on animation to execute periodically. Note that typically a 3D surface graphic should be instantiated on a graph data layer and the graph should be set to autoscale during animation.
*/

/* Declarations */

double cos(double a);
double sin(double a);

@@class() PerspectiveSurface:Object

@@method(public, class) (id)stored;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (void)finalize;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void) setGridXLength:(unsigned)xLength xMinimum:(double)xMinimum xMaximum:(double)xMaximum yLength:(unsigned)yLength yMinimum:(double)yMinimum yMaximum:(double)yMaximum;
@@method(public, instance) (void) appendValue:(double)aValue;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void) rotateToPhi:(double)phiAngle theta:(double)thetaAngle psi:(double)psiAngle;
@@method(public, instance) (void)release;

@@end

/* Execution block */

{
id mySurface;
int ix, iy;
double xValue, yValue, zValue;
unsigned animationCount;
double phiAngle;
double mod;

mySurface = [PerspectiveSurface stored];

animationCount = [mySurface animationCount];

/*
Empty the data and then append new data.
*/

[mySurface emptyData];

[mySurface setGridXLength:50 xMinimum:0.0 xMaximum:10.0 yLength:50 yMinimum:0.0 yMaximum:10.0];

mod = 0.125 * (animationCount % 80);

if(mod > 5.0)
{
mod = 10.0 - mod;
}

for(iy = 0; iy < 50; iy++)
{
yValue = iy * 0.2;

for(ix = 0; ix < 50; ix++)
{
xValue = ix * 0.2;
zValue = 5.0 * cos(xValue) + mod * sin(yValue);
[mySurface appendValue:zValue];

}
}

phiAngle = animationCount * 0.1;

//[mySurface rotateToPhi:phiAngle theta:0.3 psi:0.0];

}
